package com.xzssmk.leisure.x.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.xzssmk.leisure.x.po.SysUsr;
import com.xzssmk.leisure.x.service.CommissionService;
import com.xzssmk.leisure.x.util.DataTables;
import com.xzssmk.leisure.x.vo.CommissionVo;

@RestController
@RequestMapping("/commission")
public class ComissionController {

    @Autowired
    private CommissionService commissonService;

    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String insertCommission(CommissionVo commissionVo, HttpSession session) throws Exception {
        return JSONObject.toJSONString(commissonService.add(commissionVo, (SysUsr)session.getAttribute("usr")));
    }

    // @RequestMapping(value = "/update", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    // public String updateRole(@ModelAttribute CommissionVo commissionVo) {
    // return JSONObject.toJSONString(commissonService.update(commissionVo));
    // }

    // @RequestMapping(value = "/getCommission", method = RequestMethod.POST, produces = "application/json;
    // charset=utf-8")
    // public String getById(Integer id) {
    // return JSONObject.toJSONString(commissonService.getById(id));
    // }

    @RequestMapping(value = "/getPageList", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String getPageList(HttpServletRequest request) {
        return JSONObject.toJSONString(commissonService.getPageList(
            DataTables.getInstance(request, request.getParameter("fullName")), request.getParameter("issuePeriodId")));
    }

    @RequestMapping(value = "/commission-add.html")
    public ModelAndView addCommission() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("commission-add");
        return modelAndView;
    }

    @RequestMapping(value = "/commission-list.html")
    public ModelAndView commission() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("commission-list");
        return modelAndView;
    }
}
